package struct;

public class LinkNode<E> {
    public E val;
    public LinkNode<E> next;

    public LinkNode(E val) {
        this.val = val;
    }

    public E getVal() {
        return this.val;
    }

    public LinkNode<E> next() {
        return this.next;
    }

    public LinkNode<E> setNext(LinkNode<E> next) {
        this.next = next;
        return this.next;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(val);
        if (next != null) {
            sb.append("=>");
            LinkNode<E> temp = next;
            while (temp != null) {
                sb.append(temp.val);
                temp = temp.next();
                if (temp != null) {
                    sb.append("=>");
                }
            }
        }
        return sb.toString();
    }
}
